package com.cskaoyan.exception;

import com.cskaoyan.bean.BaseRespVo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author stone
 * @date 2022/08/10 09:56
 */
//@ControllerAdvice
//@ResponseBody
@RestControllerAdvice // = @ControllerAdvice + @ResponseBody
public class ExceptionControllerAdvice {

    //@ExceptionHandler(value = {ArithmeticException.class})
    //@ExceptionHandler({ArithmeticException.class})
    /*@ExceptionHandler(ArithmeticException.class)
    public ModelAndView arithmeticExceptionResolve() {
        return new ModelAndView("/exception.jsp");
    }*/

    /*@ExceptionHandler(ArithmeticException.class)
    public String arithmeticExceptionResolve() {
        return "/exception.jsp";
    }*/

    @ExceptionHandler(ArithmeticException.class)
    //@ResponseBody
    public BaseRespVo arithmeticExceptionResolve(ArithmeticException exception) {
        return BaseRespVo.fail();
    }

    @ExceptionHandler(CustomException.class)
    public BaseRespVo customException(CustomException exception) {
        String message = exception.getMessage();
        return BaseRespVo.fail(message);
    }
}
